package cn.ncupyh.comptest;

//求阶乘
public class FacNum {
    public static void main(String[] args) {
        //求某个数的阶乘
        int num = 4;
        int ret = facNum1(num);
        System.out.println(ret);
    }

    private static void facNum(int num) {
        int sum = 0;
        for (int i = 1; i <= num; i++) {
            int ret = 1;
            for (int j = 1; j <= i; j++) {
                ret *= j;
            }
            sum += ret;
        }
        System.out.println(num + "的阶乘为" + sum);
    }


    private static int facNum1(int num){
        //递归求
        if(num == 1) {
            return 1;
        }
        int ret = num * facNum1(num-1);
        return ret;
    }
}
